#include <QVBoxLayout>

#include <messaginglayer/contactsmodel.h>
#include <messaginglayer/cprofile.h>

#include "constants.h"
#include "contextmanager.h"
#include "icore.h"
#include "profileinfowidget.h"
#include "rightpane.h"
#include "searchlineedit.h"
#include "sidecontacts.h"
#include "uidmanager.h"

RightPane::RightPane(QWidget *parent) :
    QWidget(parent),
    m_profileInfo(new ProfileInfoWidget(this)),
    m_quickSearch(new SearchLineEdit(this)),
    m_sideContacts(new SideContacts(this))
{
    connect(parent, SIGNAL(profileChanged(CProfile*)), this, SLOT(profileChanged(CProfile*)));

    QVBoxLayout * l = new QVBoxLayout(this);    
    l->setContentsMargins(0, 0, 0, 0);

    l->addWidget(m_quickSearch);
    l->addWidget(m_profileInfo);
    l->addWidget(m_sideContacts);
    l->addSpacerItem(new QSpacerItem(15, 15, QSizePolicy::Minimum, QSizePolicy::Expanding));
}

void RightPane::profileChanged(CProfile *current)
{
    m_profileInfo->setProfile(current);
    m_sideContacts->setModel(current->contactsModel());
}

void RightPane::contextChanged()
{
    ContextManager * cm = ICore::instance()->contextManager();
    UidManager * uidm = ICore::instance()->uidManager();

    setHidden(cm->currentContext().contains(uidm->uniqueIndentifier(Constants::C_STARTUP)));
    m_sideContacts->setHidden(cm->currentContext().contains(uidm->uniqueIndentifier(Constants::C_CONTACTS)));
}
